package com.leff.cards.web.requests;

import com.leff.cards.data.User;
import com.leff.cards.util.Dictionary;
import com.leff.cards.util.Settings;
import com.leff.cards.web.WebRequest;
import com.leff.notifications.NotificationCenter;

public class LoginRequest extends WebRequest {

	public static final String LOGGED_IN = "LoginComplete";
	public static final String UPGRADE_REQUIRED = "UpgradeRequired";

	public LoginRequest(long fbid, String name) {
		super(WebCommand.LOGIN);

		mParameters.put(Parameter.FB_ID, fbid);
		mParameters.put(Parameter.NAME, name);
	}

	protected void parseResultDictionary(Dictionary dict) {
		
		boolean upgrade = (Boolean)dict.get("upgrade");
		if(upgrade) {
			Settings.setUpgrade(true);
			NotificationCenter.postNotification(UPGRADE_REQUIRED, null);
		} else {
			Settings.setUpgrade(false);
		}
		
		User U = User.fromDictionary(dict);
		NotificationCenter.postNotification(LOGGED_IN, U);
	}
}
